﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Library.Common;
using Library.Bll;

namespace HanhuaMicroCredit.BLL
{
    public class DistrictBLL
    {
        //构造函数
        public DistrictBLL() { }

        //单体模式
        private static DistrictBLL objInstance = null;
        public static DistrictBLL GetInstance()
        {
            if (objInstance == null)
                objInstance = new DistrictBLL();
            return objInstance;
        }

        public static List<Dictionary<string, object>> GetProvinces()
        {
            return DistrictBLL.GetInstance().GetBaseDistrict(0);
        }
        
        public static List<Dictionary<string, object>> GetCities(int? pid)
        {
            return DistrictBLL.GetInstance().GetBaseDistrict(pid);
        }

        public static List<Dictionary<string, object>> GetDistricts(int? pid)
        {
            return DistrictBLL.GetInstance().GetBaseDistrict(pid);
        }

        private List<Dictionary<string, object>> GetBaseDistrict(int? pid)
        {
            string table = "Base_District";
            string columns = "id, name";
            string condition = "isvalid=1";
            if (pid != null)
            {
                condition = string.Format("isvalid=1 and pid={0}", pid);
            }

            return CommonBLL.GetList(table, columns, "id asc", condition);
        }
    }
}